package useless.wecker;

import java.util.logging.Level;
import java.util.logging.Logger;

public class UselessWecker extends Thread{

    public static int DEBUG_MODE = 1;
    public static int COFFEE_RANGE = 15;
    public static String SERVER_URL = "http://uselessjunk.eu/wspellx/wecker.php";
    public static Boolean STOP = false;
    public static int MAX_RESEND = 5;
    public static String BASE_CODE = "10001";
    
    private static int startHour = 15;
    private static int startMinute = 0;
    
    public static void main(String[] args) {
        if (args.length > 0) {
            DEBUG_MODE = 0;
        }
        if (args.length == 2){
            try{
                startHour = Integer.parseInt(args[0]);
                startMinute = Integer.parseInt(args[1]);
                new UselessWecker().start();
            }
            catch(NumberFormatException ex){
                System.out.println("Fehlerhafter aufruf. Starten mit:");
                System.out.println("\" java -jar file.jar <Stunde> <Minute>\"");
                System.out.println("z.B.");
                System.out.println("\" java -jar file.jar 6 0\"");
                System.out.println("um den Wecker auf 6:00 Uhr zu stellen.");
            }

        }else {
            System.out.println("starting in debug mode. this will not trigger any switches - only console output");
            /** Von hier ab nur gezeugs zum testen in der IDE **/
            new UselessWecker().start();
            System.out.println("blubb");
            
        //Weckzeit weckzeit = new Weckzeit(15, 07);
            //Timer timer = new Timer(19, 12);
        //System.out.println(weckzeit.isInRange());

        //schalter.an(Schalter.Dose.LICHT1);
            //schalter.aus(Schalter.Dose.LICHT1);
        }
    }
    
    

    @Override
    public void run() {
        Timer timer = new Timer(startHour, startMinute);
        timer.start();
        while (!STOP){
            update();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Terminal.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        System.out.println("done");
    }

    
    
    public void update(){
        Terminal.TIME = Database.getCurrentTimeString();
        String time = Terminal.TIME;
        String lastcmd1234567890123456789 = Terminal.LAST_COMMAND;
        String lastCmdLbl = Terminal.LAST_COMMAND_LABEL;
        String next = Terminal.NEXT_TIMER;
        String nextLbl = Terminal.NEXT_TIMER_LABEL;
        String licht123 = Terminal.LICHT_STATUS;
        String kaffee123 = Terminal.KAFFEE_STATUS;
        
        System.out.println("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
        String l01 = "***********************************************************"+"\n";
        String l02 = "*                                             "+time+"    *"+"\n";
        String l03 = "* "+nextLbl+"                           "+licht123+"      *"+"\n";
        String l04 = "*   "+next+"                            "+kaffee123+"     *"+"\n";
        String l05 = "*                                                         *"+"\n";
        String l06 = "*                                                         *"+"\n";
        String l07 = "*                                                         *"+"\n";
        String l08 = "*                                                         *"+"\n";
        String l09 = "*                                                         *"+"\n";
        String l10 = "*                                                         *"+"\n";
        String l11 = "*                                                         *"+"\n";
        String l12 = "*                                                         *"+"\n";
        String l13 = "*                                                         *"+"\n";
        String l14 = "* "+lastCmdLbl+"   "+lastcmd1234567890123456789+"         *"+"\n";
        String l15 = "***********************************************************";
        
        System.out.print(l01+l02+l03+l04+l05+l06+l07+l08+l09+l10+l11+l12+l13+l14+l15);
        
    }
}
